
import * as Vuex from 'vuex'

export default Vuex.createStore({
  state: {
    nodeMap: new Map(),
    isEdit: null,
    loginUser: JSON.parse(sessionStorage.getItem('loginUser')),
    selectedNode: {},
    selectFormItem: null,
    design: {},
    token: sessionStorage.getItem('token'),
    secretKey:sessionStorage.getItem('secretKey')
  },
  mutations: {
    selectedNode(state, val) {
      state.selectedNode = val
    },
    loadForm(state, val) {
      state.design = val
    },
    setIsEdit(state, val) {
      state.isEdit = val
    },
    setUser: (state, value) => {
      state.loginUser = value
      sessionStorage.setItem('loginUser', JSON.stringify(value))
    },
    setToken: (state, value) => {
      state.token = value
      sessionStorage.setItem('token', value)
    },
    setSecretKey: (state, value) => {
      state.secretKey = value
      sessionStorage.setItem('secretKey', value)
    },
    clearUser: state => {
      state.user = null
      state.token = null
      state.secretKey=null
      sessionStorage.setItem('loginUser', null)
      sessionStorage.setItem('token', null)
      sessionStorage.setItem('secretKey', null)
    },
  },
  getters: {},
  actions: {},
  modules: {},
})
